//
//  MTextView.m
//  UT
//
//  Created by luo danal on 4/19/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "MTextView.h"

@implementation MTextView
//@synthesize text = _text;
//@synthesize font = _font;
//@synthesize selectedRange = _selectedRange;
@synthesize isTop = _isTop;
@synthesize isGold = _isGold;
@synthesize hasImage = _hasImage;
@synthesize maxLines = _maxLines;
@synthesize trancated = _trancated;

- (void)dealloc{
    [_label release];
    [_backgroundView release];
    [super dealloc];
}

- (id)initWithFrame:(CGRect)frame
{
    float margin = 8.f;
    CGRect rect = frame;
    rect.origin.x -= margin;
    rect.origin.y -= margin;
    rect.size.width += 2*margin;
    rect.size.height += margin;
    self = [super initWithFrame:rect];
    if (self) {
        // Initialization code
        self.editable = NO;
        self.scrollEnabled = NO;
        self.backgroundColor = [UIColor clearColor];
        self.textColor = [UIColor redColor];
//        _backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, rect.size.width, rect.size.height)];
        _label = [[MSRichLabel alloc] initWithFrame:CGRectMake(margin, margin, frame.size.width, frame.size.height)];
        _label.font = self.font;
        _label.textColor = self.textColor;
        _label.numberOfLines = 0;
        _label.backgroundColor = [UIColor clearColor];
        [self addSubview:_label];
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

- (void)setFrame:(CGRect)frame{
        NSLog(@"%@",NSStringFromCGRect(frame));
    float margin = 8.f;
    CGRect rect = frame;
    rect.origin.x -= margin;
    rect.origin.y -= margin;
    rect.size.width += 2*margin;
    rect.size.height += margin;
    [super setFrame:rect];
    
    _label.frame = CGRectMake(margin, margin, frame.size.width, frame.size.height);
}

- (void)setFont:(UIFont *)font{
    [super setFont:font];
    _label.font = font;
}

- (void)setText:(NSString *)text{
    [super setText:text];
    _label.text = text;
}

- (void)setBackgroundColor:(UIColor *)backgroundColor{
    [super setBackgroundColor:[UIColor clearColor]];
//    _label.backgroundColor = backgroundColor;
//    _backgroundView.backgroundColor = backgroundColor;
}

//- (void)setMaxLines:(NSInteger)maxLines{
//    _label.maxLines = maxLines;
//}
//
//- (void)setIsTop:(BOOL)isTop{
//    _label.isTop = isTop;
//}
//- (void)setIsGold:(BOOL)isGold{
//    _label.isGold = isGold;
//}
//- (void)setTrancated:(BOOL)trancated{
//    _label.trancated = trancated;
//}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    NSLog(@"%s",__func__);
}
@end
